package com.system.controller;

import com.system.entity.Question;
import com.system.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;


/**
 * 测试进行竞赛
 *
 */
@Controller
@RequestMapping("exam")
public class ExamController {

    @Autowired
    ExamService examService;

    /**
     * 跳转挑战页面
     *
     */
    @RequestMapping(value="/challenge",method = RequestMethod.GET)
    public ModelAndView challenge(ModelAndView model){
        //通过ModelAndView中的方法跳转到userAdd.jsp页面
        model.setViewName("exam/challenge");
        return model;
    }
    /**
     * 处理提交的类型选择form表单-百发百中模式
     *
     */
   @RequestMapping(value = "Type_choose")
    public String Type_choose(Question question, Model model, HttpServletRequest request){
        Question question1=examService.Type_choose(question);
        model.addAttribute("question", question1);
        if(question1.getQuestion_type().equals("选择题")){
            return "exam/test";
        }
        else if(question1.getQuestion_type().equals("判断题")){
            return "exam/test1";
        }
        else {
            return "exam/test2";
        }
    }

    /**
     * 处理提交的类型选择form表单-快马加鞭模式
     *
     */
    @RequestMapping(value = "challenge_kmjb")
    public String challenge_kmjb(Question question, Model model, HttpServletRequest request){
        Question question2=examService.Type_choose(question);
        model.addAttribute("question", question2);
        if(question2.getQuestion_type().equals("选择题")){
            return "exam/test3";
        }
        else if(question2.getQuestion_type().equals("判断题")){
            return "exam/test4";
        }
        else {
            return "exam/test5";
        }
    }





}
